{{define "Analytics"}}{{with gaAccount}}<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '{{.}}']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>{{end}}{{end}}

{{define "SearchBox"}}
  <form>
    <div class="input-group">
      <input class="form-control" name="q" autofocus="autofocus" value="{{.}}" placeholder="Search for package by import path or keyword." type="text">
      <span class="input-group-btn">
        <button class="btn btn-default" type="submit">Go!</button>
      </span>
    </div>
  </form>
{{end}}

{{define "ProjectNav"}}{{template "FlashMessages" .flashMessages}}<div class="clearfix" id="x-projnav">
  {{if .pdoc.ProjectRoot}}{{if .pdoc.ProjectURL}}<a href="{{.pdoc.ProjectURL}}"><strong>{{.pdoc.ProjectName}}:</strong></a>{{else}}<strong>{{.pdoc.ProjectName}}:</strong>{{end}}{{else}}<a href="/-/go">Go:</a>{{end}}
  {{.pdoc.Breadcrumbs templateName}}
  {{if and .pdoc.Name (or templateName "pkg.html" templateName "cmd.html")}}
  <span class="pull-right">
    {{if not .pdoc.IsCmd}}
      <a href="#pkg-index">Index</a>
      {{if .pdoc.AllExamples}}<span class="text-muted">|</span> <a href="#pkg-examples">Examples</a>{{end}}
      <span class="text-muted">|</span>
    {{end}}
    <a href="#pkg-files">Files</a>
    {{if .pkgs}}<span class="text-muted">|</span> <a href="#pkg-subdirectories">Directories</a>{{end}}
  </span>
  {{end}}
</div>{{end}}

{{define "Pkgs"}}
  <table class="table table-condensed">
  <thead><tr><th>Path</th><th>Synopsis</th></tr></thead>
  <tbody>{{range .}}<tr><td>{{if .Path|isValidImportPath}}<a href="/{{.Path}}">{{.Path|importPath}}</a>{{else}}{{.Path|importPath}}{{end}}</td><td>{{.Synopsis|importPath}}</td></tr>
  {{end}}</tbody>
  </table>
{{end}}

{{define "SearchPkgs"}}
  <table class="table table-condensed">
    <thead><tr><th>Path</th><th>Synopsis</th></tr></thead>
    <tbody>{{range .}}
      <tr><td>
        {{if .Path|isValidImportPath}}
        <a href="/{{.Path}}">{{.Path|importPath}}</a>
          <ul class="list-inline">
            <li class="additional-info">{{.ImportCount}} imports</li>
            {{if .Fork}}<li class="additional-info">· fork</li>{{end}}
            {{if .Stars}}<li class="additional-info">· {{.Stars}} stars</li>{{end}}
          </ul>
        {{else}}{{.Path|importPath}}</td>
        {{end}}
      <td class="synopsis">{{.Synopsis|importPath}}</td></tr>
    {{end}}</tbody>
  </table>
{{end}}

{{define "PkgCmdHeader"}}{{with .pdoc}}
  <title>{{.PageName}} - GoDoc</title>
  {{if .Synopsis}}
    <meta name="twitter:title" content="{{if .IsCmd}}Command{{else}}Package{{end}} {{.PageName}}">
    <meta property="og:title" content="{{if .IsCmd}}Command{{else}}Package{{end}} {{.PageName}}">
    <meta name="description" content="{{.Synopsis}}">
    <meta name="twitter:description" content="{{.Synopsis}}">
    <meta property="og:description" content="{{.Synopsis}}">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:site" content="@golang">
  {{end}}
  {{if .Errors}}<meta name="robots" content="NOINDEX">{{end}}
{{end}}{{end}}

{{define "PkgFiles"}}{{with .pdoc}}
<h4 id="pkg-files">
  {{with .BrowseURL}}<a href="{{.}}">Package Files</a>{{else}}Package Files{{end}}
  <a class="permalink" href="#pkg-files">&para;</a>
</h4>

<p>{{range .Files}}{{if .URL}}<a href="{{.URL}}">{{.Name}}</a>{{else}}{{.Name}}{{end}} {{end}}</p>
{{end}}{{end}}

{{define "PkgCmdFooter"}}
<!-- Bugs -->
{{with .pdoc}}{{with .Notes}}{{with .BUG}}
  <h3 id="pkg-note-bug">Bugs <a class="permalink" href="#pkg-note-bug">&para;</a></h3>{{range .}}<p>{{$.pdoc.SourceLink .Pos "☞" true}} {{.Body}}{{end}}
{{end}}{{end}}{{end}}

{{if $.pkgs}}<h3 id="pkg-subdirectories">Directories <a class="permalink" href="#pkg-subdirectories">&para;</a></h3>
    <table class="table table-condensed">
    <thead><tr><th>Path</th><th>Synopsis</th></tr></thead>
    <tbody>{{range $.pkgs}}<tr><td><a href="/{{.Path}}">{{relativePath .Path $.pdoc.ImportPath}}</a><td>{{.Synopsis}}</td></tr>{{end}}</tbody>
    </table>
{{end}}
<div id="x-pkginfo">
{{with $.pdoc}}
  <form name="x-refresh" method="POST" action="/-/refresh"><input type="hidden" name="path" value="{{.ImportPath}}"></form>
  <p>{{if or .Imports $.importerCount}}Package {{.Name}} {{if .Imports}}imports <a href="?imports">{{.Imports|len}} packages</a> (<a href="?import-graph">graph</a>){{end}}{{if and .Imports $.importerCount}} and {{end}}{{if $.importerCount}}is imported by <a href="?importers">{{$.importerCount}} packages</a>{{end}}.{{end}}
  {{if not .Updated.IsZero}}Updated <span class="timeago" title="{{.Updated.Format "2006-01-02T15:04:05Z"}}">{{.Updated.Format "2006-01-02"}}</span>{{if or (equal .GOOS "windows") (equal .GOOS "darwin")}} with GOOS={{.GOOS}}{{end}}.{{end}}
  <a href="javascript:document.getElementsByName('x-refresh')[0].submit();" title="Refresh this page from the source.">Refresh now</a>.
  <a href="?tools">Tools</a> for package owners.
  {{.StatusDescription}}
{{end}}
{{with $.pdoc.Errors}}
    <p>The <a href="https://golang.org/cmd/go/#Download_and_install_packages_and_dependencies">go get</a>
    command cannot install this package because of the following issues:
    <ul>
      {{range .}}<li>{{.}}{{end}}
  </ul>
{{end}}
</div>
{{end}}


{{define "FlashMessages"}}{{range .}}
  {{if eq .ID "redir"}}{{if eq (len .Args) 1}}<div class="alert alert-warning">Redirected from {{index .Args 0}}.</div>{{end}}
  {{else if eq .ID "refresh"}}{{if eq (len .Args) 1}}<div class="alert alert-danger">Error refreshing package: {{index .Args 0}}</div>{{end}}
  {{end}}
{{end}}{{end}}

